package com.dogkr.server.web;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.ResultPath;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.dogkr.common.ServerAction;
import com.dogkr.server.entity.Host;
import com.dogkr.server.entity.PetServer;
import com.dogkr.server.service.PetServerService;


@ParentPackage(value = "login-default")
@Namespace(value = "/server")
@ResultPath("/WEB-INF/jsps")
// 页面文件空间
@Results({
	
})
public class PetServerAction extends ServerAction {

	private static final long serialVersionUID = 1L;
	
	private Host host;
	
	@Autowired
	private PetServerService petServerService;
	
	@Action(value="saveserver")
	public void saveServer() {
		if(host != null) {
			if(host.getPetServerList() != null) {
				Host oldHost = getLoginUser().getHost();
				List<PetServer> serverList = this.host.getPetServerList();
				petServerService.setSysServerAttr(serverList);
				petServerService.saveHostServerWithAll(serverList, oldHost.getId());
				oldHost.setServerVal(host.getServerVal());
				oldHost.setPetServerList(serverList);
				outJson(res);
				return;
			}
		}
		outJson(this.getErrRes());
	}
	
	@Action(value="getsys")
	public void getSysServer() {
		List<PetServer> sysServerList = petServerService.selectSysPetServerWithAll();
		outJson(sysServerList);
	}

	public Host getHost() {
		return host;
	}

	public void setHost(Host host) {
		this.host = host;
	}
}
